<?php
class FrbEvenementClientController extends DooController
{
  /**
   *
   *
   * @var SimpleXMLElement
   */
  private $_xmlBD;

  private $_evenement = null;

  /**
   *
   * Description here
   * @return
   */
  public function __construct() {
    $this->_xmlBD = new SimpleXMLElement( Doo::conf()->SITE_PATH.'data/evenementDB.xml', null, true);
    $tmp = $this->_xmlBD->xpath("/evenement/item");
    foreach ($tmp as $eve){
      $this->_evenement[] = array("titre"=>(string)$eve->title, "content"=>(string)$eve->content, "image"=>(string)$eve->image);
    }
  }


  /**
   *
   * Retourne
   * @return array de array['date']=> date array['content']=> HTMLContent et array['count']=>count
   */
  public function getListeEvenement($count=5, $page=1) {
    return $this->_evenement;
  }

  /**
   *
   * Description here
   * @return
   */
  public function addEve($titre, $content, $image) {
    $item = $this->_xmlBD->addChild("item");
    $item->addChild("title", $titre);
    $item->addChild("content", $content);
    $item->addChild("image", $image);
    $this->_xmlBD->asXML(Doo::conf()->SITE_PATH.'data/evenementDB.xml');
    return true;
  }

  public function search($key){
    $arr = array();
    foreach ($this->_evenement as $eve) {
      $se = strpos($eve['content'], $key);
      if (is_numeric($se)) {
        $arr[] = $eve;
      } else {
        $se = strpos($eve['titre'], $key);
        if ( is_numeric($se)) {
          $arr[] = $eve;
        }
      }
    }
    if (sizeof($arr) == 0){
      $arr[] = array("titre"=>"Aucun résultat", "content"=>"Aucun résultat", "image"=>"02.jpg");
    }
    return $arr;
  }
}